/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HelpInternalFrame.java
 *
 * Created on Jul 25, 2010, 4:22:13 PM
 */

package org.neuralstudio;

import java.awt.BorderLayout;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.gui.HtmlPanel;
import org.lobobrowser.html.parser.DocumentBuilderImpl;
import org.lobobrowser.html.parser.InputSourceImpl;
import org.lobobrowser.html.test.SimpleHtmlRendererContext;
import org.lobobrowser.html.test.SimpleUserAgentContext;

/**
 *
 * @author william
 */
public class HelpInternalFrame extends javax.swing.JInternalFrame {

    /** Creates new form HelpInternalFrame */
    public HelpInternalFrame() {
        initComponents();
        //HtmlPanel panel = new HtmlPanel();
        //panel.setSize(jPanel19.getWidth(), jPanel18.getHeight());
        //panel.setPreferredWidth(jPanel19.getWidth());
        //jPanel19.add(panel,BorderLayout.CENTER);
        //new InputSourceImpl();
        //this.showDescription(0);
        Logger.getLogger("org.lobobrowser").setLevel(Level.WARNING);
        this.showHelp();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle(org.openide.util.NbBundle.getMessage(HelpInternalFrame.class, "HelpInternalFrame.title")); // NOI18N

        jPanel1.setLayout(new java.awt.BorderLayout());
        jScrollPane1.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 829, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
 private void showHelp() {
        //jPanel19.removeAll();
        HtmlPanel panel = new HtmlPanel();
        panel.setSize(jPanel1.getWidth(), jPanel1.getHeight());
        try{
           // new SimpleHtmlRendererContext(panel, new SimpleUserAgentContext()).navigate("http://lobobrowser.org/browser/home.jsp");

            // This panel should be added to a JFrame or
            // another Swing component.
            UserAgentContext ucontext = new SimpleUserAgentContext();
            SimpleHtmlRendererContext rcontext = new SimpleHtmlRendererContext(panel, ucontext);

            // Note that document builder should receive both contexts.
            DocumentBuilderImpl dbi = new DocumentBuilderImpl(ucontext, rcontext);
            URL myurl = null;
            /*
            switch (netType) {
                case 1:
                    myurl = this.getClass().getResource("/org/neuralstudio/resources/html/perceptron.html");
                    break;
                case 2:
                    myurl = this.getClass().getResource("/org/neuralstudio/resources/html/adaline.html");
                    break;
                case 3:
                    myurl = this.getClass().getResource("/org/neuralstudio/resources/html/mperceptron.html");
                    break;
                case 4:
                    myurl = this.getClass().getResource("/org/neuralstudio/resources/html/competitiveNetwork.html");
                    break;
                case 0:
                    myurl = this.getClass().getResource("/org/neuralstudio/resources/html/index.html");
            }
             *
             */
            myurl = this.getClass().getResource("/org/neuralstudio/resources/html/index.html");
            // A documentURI should be provided to resolve relative URIs.
            InputStreamReader reader = new InputStreamReader(myurl.openConnection().getInputStream());
            org.w3c.dom.Document document = dbi.parse(new InputSourceImpl(reader, myurl.toString()));
            // Now set document in panel. This is what causes the document to render.
            panel.setDocument(document, rcontext);


        } catch (Exception ex) {
            ex.toString();
        }

        jPanel1.add(panel,BorderLayout.CENTER);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
